package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import ui_test.TestData;
import utils.Log4Test;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: u
 * Date: 7/22/14
 * Time: 3:46 PM
 * To change this template use File | Settings | File Templates.
 */
public class SearchResultPage extends GeneralPage {
    protected By resultsTitles = By.xpath("//div[@class='search-result-goods']//div[@class='g-i-list-title']/a");


    public WebElement searchedProductTitle() {
        Log4Test.info("result product title search");
        List<WebElement> results = webDriver.findElements(resultsTitles);
        WebElement searchedTitle = null;
        if (results.size() > 0) {
            for (WebElement title : results) {
                if (title.getText().equals(TestData.firstProductName)) {
                    searchedTitle = title;
                }
            }
        }
        System.out.println(results.size());
        return searchedTitle;
    }

    public void verifySearchResultPresent() {
        Log4Test.info("verify search result present");
        Assert.assertEquals(searchedProductTitle().getText(), TestData.firstProductName);
    }

    public SearchedProductPage searchedProductNavigating() {
        Log4Test.info("To Searched Product Page Navigating");
        searchedProductTitle().click();
        return new SearchedProductPage();
    }
}                  
